<template>
<div class="mod-menu">
    <el-tree :data="dataList" node-key="catId" :props="defaultProps" @node-click="onNodeClick">
        <span class="custom-tree-node" slot-scope="{ node }">
            <span>{{ node.label }}</span>
        </span>
    </el-tree>
</div>
</template>

<script>
export default {
    data() {
        return {
            dataList: [],
            dataListLoading: false,
            formLabelWidth: '120px',
            defaultProps: {
                key: 'catId',
                children: 'subList',
                label: 'name'
            }
        }
    },
    async activated() {
        this.getDataList()
    },
    methods: {
        // 获取数据列表
        getDataList() {
            this.dataListLoading = true
            this.$http({
                url: this.$http.adornUrl('/product/category/list/tree'),
                method: 'get',
                params: this.$http.adornParams()
            }).then(({
                //解构函数
                data
            }) => {
                this.dataList = data.data
            })
        },

        onNodeClick(data, node, component) {
            console.log("触发了node-click事件....")
            this.$emit("tree-node-click", data, node, component)
        }
    }
}
</script>

<style>
.el-row {
    margin-bottom: 20px;
}

.el-col {
    border-radius: 4px;
}

.bg-purple-dark {
    background: #99a9bf;
}

.bg-purple {
    background: #d3dce6;
}

.bg-purple-light {
    background: #e5e9f2;
}

.grid-content {
    border-radius: 4px;
    min-height: 36px;
}

.row-bg {
    padding: 10px 0;
    background-color: #f9fafc;
}
</style>
